(function() {
    'use strict';

    angular
        .module('milkbeeApp')
        .config(stateConfig);

    stateConfig.$inject = ['$stateProvider'];

    function stateConfig($stateProvider) {
        $stateProvider.state('instants', {
            parent: 'my',
            url: '/instant',
            data: {
                authorities: ['ROLE_USER'],
                pageTitle: 'tracker.title'
            },
            views: {
                'content@': {
                    templateUrl: 'app/my/instant/instants.html',
                    controller: 'InstantController',
                    controllerAs: 'vm'
                }
            },
            resolve: {
                mainTranslatePartialLoader: ['$translate', '$translatePartialLoader', function ($translate, $translatePartialLoader) {
                    $translatePartialLoader.addPart('tracker');
                    return $translate.refresh();
                }],
                translatePartialLoader: ['$translate', '$translatePartialLoader', function ($translate, $translatePartialLoader) {
	                $translatePartialLoader.addPart('message');
	                $translatePartialLoader.addPart('global');
	                return $translate.refresh();
                }]
            },
            onEnter: ['InstantService', function(InstantService) {
            	InstantService.subscribe();
            }],
            onExit: ['InstantService', function(InstantService) {
            	InstantService.unsubscribe();
            }]
        })
        
        .state('instants.gift', {
            parent: 'instants',
            url: '/instant/gift',
            data: {
                authorities: ['ROLE_USER']
            },
            params: {
                page: {
                    value: '1',
                    squash: true
                },
                userId:'0'
            },
            onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) {
                $uibModal.open({
                    templateUrl: 'app/my/instant/instant-gift-dialog.html',
                    controller: 'InstantGiftDialogController',
                    controllerAs: 'vm',
                    backdrop: 'static',
                    size: 'lg',
                    resolve: {
                    	pagingParams: ['$stateParams', 'PaginationUtil', function ($stateParams, PaginationUtil) {
                            return {
                                page: PaginationUtil.parsePage($stateParams.page),
                                sort: '',
                                predicate: PaginationUtil.parsePredicate(''),
                                ascending: PaginationUtil.parseAscending(''),
                                search: $stateParams.search,
                                userId:$stateParams.userId
                            };
                        }],
                        entity: function () {
                            return {
                                
                            };
                        } 
                    }
                }).result.then(function() {
                    $state.go('instants', null, { reload: 'instants' });
                }, function() {
                    $state.go('instants');
                });
            }]
        });
    }
})();
